package cst.neu.yuejian_31.fragment;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.adapter.AOrderAdapter;
import cst.neu.yuejian_31.adapter.AllOrderAdapter;
import cst.neu.yuejian_31.bean.AOrderBean;
import cst.neu.yuejian_31.bean.COrderBean;
import cst.neu.yuejian_31.iface.AOrderListener;
import cst.neu.yuejian_31.model.AOrderModel;
import cst.neu.yuejian_31.model.COrderModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class AOrderFragment extends BaseFragment implements AOrderListener {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private View view=null;
    private List<AOrderBean> list=null;
    private Context context;
    private AOrderAdapter aOrderAdapter;
    private String userId=null;


    public String getUserId()
    {
        SharedPreferences sp;
        sp=context.getSharedPreferences("login", Context.MODE_PRIVATE);
        return  sp.getString("user_id","");
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_aorder, container, false);
        context=this.getActivity();
        userId=getUserId();
        AOrderModel aOrderModel=new AOrderModel();
        aOrderModel.getAOrder(userId,this);
        initView();
        return view;
    }
    private void initView() {

        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_aorder);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        aOrderAdapter=new AOrderAdapter(context);
        aOrderAdapter.setList(list);
        recyclerView.setAdapter(aOrderAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));
    }

    @Override
    public void onSuccess(List<AOrderBean> aOrderBeen) {
        list=aOrderBeen;
        aOrderAdapter.setList(list);


    }

    @Override
    public void onFail(String msg) {

    }
}
